package 刷题10月.leecodehot100;

import java.util.ArrayList;
import java.util.List;

// https://leetcode-cn.com/problems/subsets/
public class 回朔78子集1017 {
    class Solution {
        //回朔
        List<List<Integer>>ans=new ArrayList();
        public List<List<Integer>> subsets(int[] nums) {
            dfs(nums,0,new ArrayList());
            return ans;
        }
        public void dfs(int[]nums,int index,List<Integer>list){
            if(index==nums.length){  //base case
                ans.add(new ArrayList(list));
                return;
            }
            list.add(nums[index]); //要这个数
            dfs(nums,index+1,list);//递归下去
            list.remove(list.size()-1);//不要这个数
            dfs(nums,index+1,list);//递归下去
        }
    }
/*
class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        res.add(new ArrayList<>());
        for (int i = 0; i < nums.length; i++) {
           int all = res.size();
            for (int j = 0; j < all; j++) {
                List<Integer> tmp = new ArrayList<>(res.get(j));
                tmp.add(nums[i]);
                res.add(tmp);
            }
        }
        return res;
    }
}
*/

}
